/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.elicitor.lieDetection.fromDeviation;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 *
 * @author dileepa
 */
public class LieDetectionDeviationAlgo {
    
    
   String realTimeFileLoc;
   
  
   
    
    public LieDetectionDeviationAlgo(String string) {
        
        this.realTimeFileLoc = string;
        
        
    }
    
    public String exatractDataToMap(String clipLoc,  HashMap <String, List<Double>> trueFalseMap){
        
        Scanner scanner = null;
        File file = new File(realTimeFileLoc);
        List <Double>realtimeDataList = new ArrayList<Double>();
        String suitableEmotion = null;
        
        
        try {
 
             scanner = new Scanner(file);
 
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                String result[] = line.split(",");
                
        if(result.length == 24){ 
            for (String s : result){
                        realtimeDataList.add(Double.parseDouble(s));

            }
        }
            }
            
            trueFalseMap.put(clipLoc, realtimeDataList);
            System.out.println(trueFalseMap);
            
            
          
            
        }
            
            catch (Exception e){
                System.err.println(e.getMessage());
            }
        finally{
            scanner.close();
        }
        
        return suitableEmotion;
       
    }

    private Double calcuDistance(List<Double> realtimeDataList, Double emotion[]) {
        
        double d=0;
        
        for (int i=0; i<17;i++){
            
           d = d + (realtimeDataList.get(i)-emotion[i])*(realtimeDataList.get(i)-emotion[i]); 
        }
        
        return d;
    }

    

    public HashMap <String, Double> calculateDeviationofVoice(HashMap<String, List<Double>> trueFalseMap) {

        HashMap <String, Double> deviationMap = new HashMap <String, Double>();
    
        ArrayList <Double> trueData = (ArrayList <Double>) trueFalseMap.get("clip0");
        
        int j=0;
        for (String key : trueFalseMap.keySet()){
            
        double d=0;
        
        for (int i=0; i<24;i++){
            
           d = d + (trueFalseMap.get(key).get(i)-trueData.get(i))*(trueFalseMap.get(key).get(i)-trueData.get(i)); 
           
        }
        d = Math.sqrt(d);
         
            deviationMap.put(key,d);
            j++;
        }
        
        return deviationMap;
        
    }
    
    
}
